package com.example.administrator.mvpnetproject.login;

import com.example.administrator.mvpnetproject.AppService;
import com.example.lib_base.base.mvp.presenter.BasePresenter;
import com.example.lib_base.base.mvp.view.BaseMvpActivity;
import com.example.lib_base.base.network.callback.RxRequestCallBack;
import com.example.lib_base.base.network.clicent.HttpClient;
import com.example.lib_base.base.network.entity.HttpResult;

/**
 * @author yedong
 * @date 2019/1/11
 */
public class LoginPresenter extends BasePresenter<ILoginView> {


    public LoginPresenter(BaseMvpActivity act) {
        super(act);
    }

    public void login(String userName, String password) {
        LoginRequest request = new LoginRequest(userName,password);
        addActSubscribe(HttpClient.getService(AppService.class).login(request.getParams()), new RxRequestCallBack<LoginModel>() {
            @Override
            public void onSuccess(HttpResult<LoginModel> httpResult) {
                getView().onLoginSuccess(httpResult.getData());
            }

            @Override
            public void onFailed(HttpResult<LoginModel> httpResult) {
                getView().onLoginFail();
            }
        });
    }
}
